import React,{useRef} from 'react'
import {connect} from 'react-redux'
// rfcred  rfcred
const Test0203 =(props)=> {
    const inf  = useRef()
    const { list} = props
    return (
        <div>
            <h1>react-redux练习</h1>
            <input type="text"  ref={inf}  />
            <button onClick={()=>props.add(inf)} > 添加</button>
            <ul>
                {
                    list.map((item,i) => {
                         return <li key={i} > {item} </li> 
                    })
                }
            </ul>
        </div>
    )
}
// 这个新对象给了props
const mapStateToProps = (state) => ({...state})
const mapDispatchToProps = {
      add:(inf) => {
        //   返回一个action的对象  { type, payload }
          return {type:"add",payload:inf.current.value}
      }  
}

export default connect(mapStateToProps, 
    mapDispatchToProps)(Test0203)



